package com.example.demo.advice;

import com.example.demo.exception.ThrowableException;
import com.example.demo.pojo.ResultPojo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
@Order(99)
public class DefaultAdvice {
    @ExceptionHandler(ThrowableException.class)
    @ResponseBody
    public ResultPojo dealMethodError(ThrowableException e) {
        System.out.println("兜底的异常处理");
        String errCode = e.getErrCode();
        String errMsg = e.getErrMsg();
        log.error(errCode.concat(errMsg));
        log.error(errCode, e.getThrowable());
        return new ResultPojo(errCode, errMsg);
    }
}
